﻿using LJ.Abstractions.Pack.Attributes;
using LJ.EventBus.Abstractions;
using LJ.EventBus.Abstractions.Pack;
using LJ.EventBus.FastDog.Internal;
using LJ.EventBus.FastDog.Transport.Abstractions.Pack;
using LJ.FaultHandler.Abstractions.Pack;
using LJ.IdGenerator.Abstractions.Pack;
using Microsoft.Extensions.DependencyInjection;

namespace LJ.EventBus.FastDog.Pack;

[DependPack(typeof(IIdGeneratorPack))]
[DependPack(typeof(IFaultHandlerPack))]
[DependPack(typeof(IEventBusFastDogTransportPack))]
public abstract class EventBusFastDogPackBase : PackBase, IEventBusPack
{
    public override void Add(IPackContext packContext)
    {
        var eventBusSubscribeManager = new EventHandlerManager(packContext.DependencyManager, packContext.ReflectionManager);
        packContext.DependencyManager.ServiceCollection.AddSingleton<IEventHandlerManager>(eventBusSubscribeManager);

        packContext.DependencyManager.ServiceCollection.AddSingleton<IMessageSerializer, MessageSerializer>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IEventBusSubscribe, EventBusSubscribe>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IEventHandlerInvoker, EventHandlerInvoker>();

        packContext.DependencyManager.ServiceCollection.AddTransient<IMessageListener, MessageListener>();

        packContext.DependencyManager.ServiceCollection.AddScoped<IEventBusPublisher, EventBusPublisher>();


        packContext.DependencyManager.ServiceCollection.AddSingleton<IPackProcessingServer, EventBusFastDogPackProcessingServer>();
    }

    public override void Use(IPackProvider packProvider)
    {
    }
}
